import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class demo06 {
    //阻塞队列的例子——消费者与生产者
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque=new LinkedBlockingDeque<>();

        //消费者
        Thread t1=new Thread(()->{
            while (true){
                try {
                    int value = blockingDeque.take();
                    System.out.println("消费元素"+value);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();

        //生产者
        Thread t2=new Thread(()->{
            int value=1;
            while (true){
                try {
                    System.out.println("生产元素："+value);
                    blockingDeque.put(value);
                    value++;
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t2.start();

        //生产者每一秒生产一个元素
        //消费者直接消费不受限制
    }
}
